(bug 4535) Warn user when editing CSS or JS subpage of a skin that doesn't exist
authorRob Church <robchurch@users.mediawiki.org>
Thu, 23 Feb 2006 14:37:51 +0000 (14:37 +0000)
committerRob Church <robchurch@users.mediawiki.org>
Thu, 23 Feb 2006 14:37:51 +0000 (14:37 +0000)
RELEASE-NOTES
includes/EditPage.php
includes/Title.php
languages/Messages.php

index fb6ba7f..a276998 100644 (file)
@@ -649,6 +649,7 @@ fully support the editing toolbar, but was found to be too confusing.
 * Added article size limit, $wgMaxArticleSize
 * (bug 4974) Don't follow redirected talk page on "new messages" link
 * (bug 4970) Make category paging limits configurable
+* (bug 4535) Warn user when editing CSS or JS subpage of a skin that doesn't exist
 
 === Caveats ===
 
index 1aad75f..47f5311 100644 (file)
@@ -250,7 +250,8 @@ class EditPage {
 
                $this->isConflict = false;
                // css / js subpages of user pages get a special treatment
-               $this->isCssJsSubpage = $wgTitle->isCssJsSubpage();
+               $this->isCssJsSubpage      = $wgTitle->isCssJsSubpage();
+               $this->isValidCssJsSubpage = $wgTitle->isValidCssJsSubpage();
 
                /* Notice that we can't use isDeleted, because it returns true if article is ever deleted
                 * no matter it's current state
@@ -747,12 +748,19 @@ class EditPage {
 
                if( wfReadOnly() ) {
                        $wgOut->addWikiText( wfMsg( 'readonlywarning' ) );
-               } else if ( $this->isCssJsSubpage and 'preview' != $this->formtype) {
-                       $wgOut->addWikiText( wfMsg( 'usercssjsyoucanpreview' ));
-               } else if( $wgUser->isAnon() && $this->formtype != 'preview' ) {
+               } elseif( $wgUser->isAnon() && $this->formtype != 'preview' ) {
                        $wgOut->addWikiText( wfMsg( 'anoneditwarning' ) );
+               } else {
+                       if( $this->isCssJsSubpage && $this->formtype != 'preview' ) {
+                               # Check the skin exists
+                               if( $this->isValidCssJsSubpage ) {
+                                       $wgOut->addWikiText( wfMsg( 'usercssjsyoucanpreview' ) );
+                               } else {
+                                       $wgOut->addWikiText( wfMsg( 'userinvalidcssjstitle', $this->mTitle->getSkinFromCssJsSubpage() ) );
+                               }
+                       }
                }
-               
+                       
                if( $this->mTitle->isProtected( 'edit' ) ) {
                        if( $this->mTitle->isSemiProtected() ) {
                                $notice = wfMsg( 'semiprotectedpagewarning' );
index d65176e..f2349bc 100644 (file)
@@ -1105,6 +1105,22 @@ class Title {
        function isCssJsSubpage() {
                return ( NS_USER == $this->mNamespace and preg_match("/\\.(css|js)$/", $this->mTextform ) );
        }
+       /**
+        * Is this a *valid* .css or .js subpage of a user page?
+        * Check that the corresponding skin exists
+        */
+       function isValidCssJsSubpage() {
+               global $wgValidSkinNames;
+               return( $this->isCssJsSubpage() && array_key_exists( $this->getSkinFromCssJsSubpage(), $wgValidSkinNames ) );
+       }
+       /**
+        * Trim down a .css or .js subpage title to get the corresponding skin name
+        */
+       function getSkinFromCssJsSubpage() {
+               $subpage = explode( '/', $this->mTextform );
+               $subpage = $subpage[ count( $subpage ) - 1 ];
+               return( str_replace( array( '.css', '.js' ), array( '', '' ), $subpage ) );
+       }
        /**
         * Is this a .css subpage of a user page?
         * @return bool
index 9db809c..ca7d097 100644 (file)
@@ -488,6 +488,7 @@ If you are here by mistake, just click your browser's '''back''' button.",
 'usercssjsyoucanpreview' => '<strong>Tip:</strong> Use the \'Show preview\' button to test your new CSS/JS before saving.',
 'usercsspreview' => '\'\'\'Remember that you are only previewing your user CSS, it has not yet been saved!\'\'\'',
 'userjspreview' => '\'\'\'Remember that you are only testing/previewing your user JavaScript, it has not yet been saved!\'\'\'',
+'userinvalidcssjstitle' => "'''Warning:''' There is no skin \"$1\". Remember that custom .css and .js pages use a lowercase title, e.g. User:Foo/monobook.css as opposed to User:Foo/Monobook.css.",
 'updated' => '(Updated)',
 'note' => '<strong>Note:</strong>',
 'previewnote' => '<strong>This is only a preview; changes have not yet been saved!</strong>',